using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Threading;
using System.Globalization;
using System.Collections;
using System.Web.Security;

using Cuyahoga.Core;
using Cuyahoga.Core.Domain;
using Cuyahoga.Core.Service.SiteStructure;
using Cuyahoga.Core.Util;
using Cuyahoga.Web.UI;
using Cuyahoga.Web.Util;
using Cuyahoga.Web.Components;

namespace Cuyahoga.Web
{
    public partial class WidgetContainer : System.Web.UI.UserControl
    {
        private BaseModuleControl _moduleControl;
        private int _id;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public BaseModuleControl ModuleControl
        {
            set { _moduleControl = value; }
            get { return _moduleControl; }
        }
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            //Literal lt = new Literal();
            
            //lt.Text = WidgetInstance.Content+"<br />";
            //lt.ID = "Widget" + WidgetInstance.Id.ToString();
            //if (!string.IsNullOrEmpty(WidgetInstance.Url))
            //{
            //    System.Web.UI.Control ct = LoadControl(WidgetInstance.Url);
            //    ct.ID = "Widget" + WidgetInstance.Id.ToString();
            //    PanelBody.Controls.Add(ct);
            //}
            //else
            //{
            //    PanelBody.Controls.Add(lt);
            //}
            if (ModuleControl != null)
            {
                PanelBody.Controls.Add(ModuleControl);
                liTitle.Text = ModuleControl.Module.Section.Title;
            }
            else
            {
                System.Web.UI.Control ct = LoadControl("~/ComplexControlForTest/WidgetList.ascx");
                liTitle.Text = "Test Complex Control "+Id;
                ct.ID = "Widget" + Id.ToString();
                PanelBody.Controls.Add(ct);
            }
        }

        protected void EditWidget_Click(object sender, EventArgs e)
        {

        }

        protected void CollapseWidget_Click(object sender, EventArgs e)
        {

        }

        protected void ExpandWidget_Click(object sender, EventArgs e)
        {

        }

        protected void CloseWidget_Click(object sender, EventArgs e)
        {

        }

        public override void RenderControl(HtmlTextWriter writer)
        {
            if (ModuleControl != null)
            {
                writer.AddAttribute("InstanceId", this.ModuleControl.Module.Section.Id.ToString());
            }
            else
            {
                writer.AddAttribute("InstanceId", Id.ToString());
            }
            //writer.AddAttribute("column", this.ModuleControl.Module.Section.Id.ToString());
            base.RenderControl(writer);
        }    
    }
}